package cn.lee.test.common.base.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.sql.Update;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author : lichl(李承霖)
 * create: 2021/4/15 11:10
 * 抽象pojo类,为pojo生成固定的字段
 */

@Getter
@Setter
@ToString
@MappedSuperclass
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public abstract class BaseJpaModel implements CurdModel<Long>, Serializable{
  
  @Column(updatable = false, nullable = false)
  @ApiModelProperty(value = "创建时间戳", example = "0")
  private long createdAt = 0;
  
  @Column(nullable = false)
  @ApiModelProperty(value = "更新时间戳", example = "0")
  private long updatedAt = 0;
  
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @ApiModelProperty(value = "ID-唯一标识", example = "0")
  @NotNull(groups = {Update.class})
  private Long id;
  
  @Override
  @Transient
  @ApiModelProperty(hidden = true)
  public boolean isValidKey(){
    return id != null && id > 0;
  }
}
